package cn.niit.edu.mobile.studyDemo.service.impl;

import cn.niit.edu.mobile.studyDemo.dto.*;
import cn.niit.edu.mobile.studyDemo.mapper.HeroMapper;
import cn.niit.edu.mobile.studyDemo.service.HeroService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("HeroService")
@SuppressWarnings("ALL")/*忽略父类查找*/
public class HeroServiceImpl implements HeroService {
    //使用构造器注入的方式，注入Mapper
    private final HeroMapper heroMapper;
    public HeroServiceImpl(HeroMapper heroMapper) {
        this.heroMapper = heroMapper;
    }

    /*创建一个新皮肤*/
    @Override
    public SkinInfo createSkin(SkinInfo skinInfo) {
        Integer rowCount = this.heroMapper.createSkin(skinInfo);
        if (rowCount >0){
            return skinInfo;
        }
        return null;
    }

    /*更新指定英雄次要分类*/
    @Override
    public HeroInfo updateHeroType(Integer id, Integer newTypeId) {
        Integer rowCount = this.heroMapper.updateHeroType(id, newTypeId);
        if (rowCount > 0){
            return this.heroMapper.getHeroInfo(id);
        }
        return null;
    }

    /*统计各类型英雄数量，按类型id升序排列*/
    @Override
    public List<HeroTypeData> getTypeCount() {
        return heroMapper.getTypeCount();
    }

    /*按分类名称查询英雄列表，分页返回*/
    @Override
    public Page<HeroInfo> getTypeName(String typeName, Integer page, Integer size) {
        Integer start = page * size;
        //分页列表
        List<HeroInfo> typeNameDataList = this.heroMapper.getTypeName(typeName, page, size);
        //记录总数
        Long totalCount = this.heroMapper.getHeroTypeCount(typeName);
        //列表+分页信息+记录总数 产生分页对象
        return new PageImpl<>(typeNameDataList, PageRequest.of(page,size),totalCount);
    }

    /*获取一个战士*/
    @Override
    public HeroInfo getHeroTeam() {

        return heroMapper.getHeroTeam();
    }
    /*获取一个法师*/
    @Override
    public HeroInfo getMage() {
        return heroMapper.getMage();
    }
    /*获取一个射手*/
    @Override
    public HeroInfo getStriker() {
        return heroMapper.getStriker();
    }
    /*获取一个辅助*/
    @Override
    public HeroInfo getAuxiliary() {
        return heroMapper.getAuxiliary();
    }
    /*获取一个刺客*/
    @Override
    public HeroInfo getAssassin() {
        return heroMapper.getAssassin();
    }
}
